<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="分配到机构的id" prop="bankId">
        <el-input
          v-model="queryParams.bankId"
          placeholder="请输入分配到机构的id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="文件名" prop="fileName">
        <el-input
          v-model="queryParams.fileName"
          placeholder="请输入文件名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="统一代码" prop="corpCredit">
        <el-input
          v-model="queryParams.corpCredit"
          placeholder="请输入统一代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分配到用户的id" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入分配到用户的id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="批次号(一次上传算)" prop="batchId">
        <el-input
          v-model="queryParams.batchId"
          placeholder="请输入批次号(一次上传算)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="排序字段" prop="orderNum">
        <el-input
          v-model="queryParams.orderNum"
          placeholder="请输入排序字段"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系电话" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入联系电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="录入时间" prop="createTime">
        <el-date-picker clearable
          v-model="queryParams.createTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择录入时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="录入人" prop="createUser">
        <el-input
          v-model="queryParams.createUser"
          placeholder="请输入录入人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="修改时间" prop="updateTime">
        <el-date-picker clearable
          v-model="queryParams.updateTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择修改时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="修改人" prop="updateUser">
        <el-input
          v-model="queryParams.updateUser"
          placeholder="请输入修改人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="区域" prop="region">
        <el-input
          v-model="queryParams.region"
          placeholder="请输入区域"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经度" prop="longitude">
        <el-input
          v-model="queryParams.longitude"
          placeholder="请输入经度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="纬度" prop="latitude">
        <el-input
          v-model="queryParams.latitude"
          placeholder="请输入纬度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="距离" prop="distance">
        <el-input
          v-model="queryParams.distance"
          placeholder="请输入距离"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="简称" prop="shortName">
        <el-input
          v-model="queryParams.shortName"
          placeholder="请输入简称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="录入人所在银行ID" prop="createBankId">
        <el-input
          v-model="queryParams.createBankId"
          placeholder="请输入录入人所在银行ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="走访时间间隔" prop="visitInterval">
        <el-input
          v-model="queryParams.visitInterval"
          placeholder="请输入走访时间间隔"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="删除用户" prop="deleteUser">
        <el-input
          v-model="queryParams.deleteUser"
          placeholder="请输入删除用户"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分配至支行名称" prop="branchOrgName">
        <el-input
          v-model="queryParams.branchOrgName"
          placeholder="请输入分配至支行名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分支行全路径" prop="branchOrgPath">
        <el-input
          v-model="queryParams.branchOrgPath"
          placeholder="请输入分支行全路径"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="删除标识" prop="isDelete">
        <el-input
          v-model="queryParams.isDelete"
          placeholder="请输入删除标识"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['visitcorp:CORP:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['visitcorp:CORP:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['visitcorp:CORP:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['visitcorp:CORP:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="CORPList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="分配到机构的id" align="center" prop="bankId" />
      <el-table-column label="用途" align="center" prop="purpose" />
      <el-table-column label="文件名" align="center" prop="fileName" />
      <el-table-column label="企业名称" align="center" prop="corpName" />
      <el-table-column label="统一代码" align="center" prop="corpCredit" />
      <el-table-column label="分配到用户的id" align="center" prop="userId" />
      <el-table-column label="批次号(一次上传算)" align="center" prop="batchId" />
      <el-table-column label="排序字段" align="center" prop="orderNum" />
      <el-table-column label="企业类型" align="center" prop="corpType" />
      <el-table-column label="联系电话" align="center" prop="phone" />
      <el-table-column label="录入时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="录入人" align="center" prop="createUser" />
      <el-table-column label="修改时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改人" align="center" prop="updateUser" />
      <el-table-column label="区域" align="center" prop="region" />
      <el-table-column label="经度" align="center" prop="longitude" />
      <el-table-column label="纬度" align="center" prop="latitude" />
      <el-table-column label="距离" align="center" prop="distance" />
      <el-table-column label="企业地址" align="center" prop="address" />
      <el-table-column label="简称" align="center" prop="shortName" />
      <el-table-column label="录入人所在银行ID" align="center" prop="createBankId" />
      <el-table-column label="走访时间间隔" align="center" prop="visitInterval" />
      <el-table-column label="导入类型" align="center" prop="importType" />
      <el-table-column label="删除用户" align="center" prop="deleteUser" />
      <el-table-column label="分配至支行名称" align="center" prop="branchOrgName" />
      <el-table-column label="分支行全路径" align="center" prop="branchOrgPath" />
      <el-table-column label="删除标识" align="center" prop="isDelete" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['visitcorp:CORP:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['visitcorp:CORP:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改营销走访企业名单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="分配到机构的id" prop="bankId">
          <el-input v-model="form.bankId" placeholder="请输入分配到机构的id" />
        </el-form-item>
        <el-form-item label="用途" prop="purpose">
          <el-input v-model="form.purpose" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="文件名" prop="fileName">
          <el-input v-model="form.fileName" placeholder="请输入文件名" />
        </el-form-item>
        <el-form-item label="企业名称" prop="corpName">
          <el-input v-model="form.corpName" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="统一代码" prop="corpCredit">
          <el-input v-model="form.corpCredit" placeholder="请输入统一代码" />
        </el-form-item>
        <el-form-item label="分配到用户的id" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入分配到用户的id" />
        </el-form-item>
        <el-form-item label="批次号(一次上传算)" prop="batchId">
          <el-input v-model="form.batchId" placeholder="请输入批次号(一次上传算)" />
        </el-form-item>
        <el-form-item label="排序字段" prop="orderNum">
          <el-input v-model="form.orderNum" placeholder="请输入排序字段" />
        </el-form-item>
        <el-form-item label="联系电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="录入人" prop="createUser">
          <el-input v-model="form.createUser" placeholder="请输入录入人" />
        </el-form-item>
        <el-form-item label="修改人" prop="updateUser">
          <el-input v-model="form.updateUser" placeholder="请输入修改人" />
        </el-form-item>
        <el-form-item label="区域" prop="region">
          <el-input v-model="form.region" placeholder="请输入区域" />
        </el-form-item>
        <el-form-item label="经度" prop="longitude">
          <el-input v-model="form.longitude" placeholder="请输入经度" />
        </el-form-item>
        <el-form-item label="纬度" prop="latitude">
          <el-input v-model="form.latitude" placeholder="请输入纬度" />
        </el-form-item>
        <el-form-item label="距离" prop="distance">
          <el-input v-model="form.distance" placeholder="请输入距离" />
        </el-form-item>
        <el-form-item label="企业地址" prop="address">
          <el-input v-model="form.address" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="简称" prop="shortName">
          <el-input v-model="form.shortName" placeholder="请输入简称" />
        </el-form-item>
        <el-form-item label="录入人所在银行ID" prop="createBankId">
          <el-input v-model="form.createBankId" placeholder="请输入录入人所在银行ID" />
        </el-form-item>
        <el-form-item label="走访时间间隔" prop="visitInterval">
          <el-input v-model="form.visitInterval" placeholder="请输入走访时间间隔" />
        </el-form-item>
        <el-form-item label="删除用户" prop="deleteUser">
          <el-input v-model="form.deleteUser" placeholder="请输入删除用户" />
        </el-form-item>
        <el-form-item label="分配至支行名称" prop="branchOrgName">
          <el-input v-model="form.branchOrgName" placeholder="请输入分配至支行名称" />
        </el-form-item>
        <el-form-item label="分支行全路径" prop="branchOrgPath">
          <el-input v-model="form.branchOrgPath" placeholder="请输入分支行全路径" />
        </el-form-item>
        <el-form-item label="删除标识" prop="isDelete">
          <el-input v-model="form.isDelete" placeholder="请输入删除标识" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCORP, getCORP, delCORP, addCORP, updateCORP } from "@/api/visitcorp/CORP";

export default {
  name: "CORP",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 营销走访企业名单表格数据
      CORPList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        bankId: null,
        purpose: null,
        fileName: null,
        corpName: null,
        corpCredit: null,
        userId: null,
        batchId: null,
        orderNum: null,
        corpType: null,
        phone: null,
        createTime: null,
        createUser: null,
        updateTime: null,
        updateUser: null,
        region: null,
        longitude: null,
        latitude: null,
        distance: null,
        address: null,
        shortName: null,
        createBankId: null,
        visitInterval: null,
        importType: null,
        deleteUser: null,
        branchOrgName: null,
        branchOrgPath: null,
        isDelete: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        bankId: [
          { required: true, message: "分配到机构的id不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询营销走访企业名单列表 */
    getList() {
      this.loading = true;
      listCORP(this.queryParams).then(response => {
        this.CORPList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        bankId: null,
        purpose: null,
        fileName: null,
        corpName: null,
        corpCredit: null,
        userId: null,
        batchId: null,
        orderNum: null,
        corpType: null,
        phone: null,
        createTime: null,
        createUser: null,
        updateTime: null,
        updateUser: null,
        region: null,
        longitude: null,
        latitude: null,
        distance: null,
        address: null,
        shortName: null,
        createBankId: null,
        visitInterval: null,
        importType: null,
        deleteUser: null,
        branchOrgName: null,
        branchOrgPath: null,
        isDelete: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加营销走访企业名单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCORP(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改营销走访企业名单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCORP(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCORP(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除营销走访企业名单编号为"' + ids + '"的数据项？').then(function() {
        return delCORP(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('visitcorp/CORP/export', {
        ...this.queryParams
      }, `CORP_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
